package c.e.a.b.f.b;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import c.e.a.b.b.i.a;
import c.e.a.b.b.k.b;
import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;
import java.util.List;
import java.util.Objects;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class m4 {
    public final u4 a;

    public m4(u4 u4Var) {
        this.a = u4Var;
    }

    public final void a(String str) {
        if (str == null || str.isEmpty()) {
            this.a.d().j.a("Install Referrer Reporter was called with invalid app package name");
            return;
        }
        this.a.a().g();
        if (b()) {
            l4 l4Var = new l4(this, str);
            this.a.a().g();
            Intent intent = new Intent("com.google.android.finsky.BIND_GET_INSTALL_REFERRER_SERVICE");
            String str2 = "com.android.vending";
            intent.setComponent(new ComponentName(str2, "com.google.android.finsky.externalreferrer.GetInstallReferrerService"));
            PackageManager packageManager = this.a.a.getPackageManager();
            if (packageManager == null) {
                this.a.d().j.a("Failed to obtain Package Manager to verify binding conditions for Install Referrer");
                return;
            }
            List queryIntentServices = packageManager.queryIntentServices(intent, 0);
            if (queryIntentServices == null || queryIntentServices.isEmpty()) {
                this.a.d().l.a("Play Service for fetching Install Referrer is unavailable on device");
                return;
            }
            ServiceInfo serviceInfo = ((ResolveInfo) queryIntentServices.get(0)).serviceInfo;
            if (serviceInfo != null) {
                String str3 = serviceInfo.packageName;
                if (serviceInfo.name != null && str2.equals(str3) && b()) {
                    Intent intent2 = new Intent(intent);
                    try {
                        a a = a.a();
                        Context context = this.a.a;
                        Objects.requireNonNull(a);
                        context.getClass().getName();
                        this.a.d().n.b("Install Referrer Service is", a.b(context, intent2, l4Var, 1) ? "available" : "not available");
                        return;
                    } catch (Exception e) {
                        this.a.d().f.b("Exception occurred while binding to Install Referrer Service", e.getMessage());
                        return;
                    }
                }
                this.a.d().i.a("Play Store version 8.3.73 or higher required for Install Referrer");
            }
            return;
        }
        this.a.d().l.a("Install Referrer Reporter is not available");
    }

    public final boolean b() {
        boolean z = false;
        try {
            c.e.a.b.b.k.a a = b.a(this.a.a);
            if (a == null) {
                this.a.d().n.a("Failed to get PackageManager for Install Referrer Play Store compatibility check");
                return false;
            }
            if (a.a.getPackageManager().getPackageInfo("com.android.vending", AesLen.ROOTKEY_COMPONET_LEN).versionCode >= 80837300) {
                z = true;
            }
            return z;
        } catch (Exception e) {
            this.a.d().n.b("Failed to retrieve Play Store version for Install Referrer", e);
            return false;
        }
    }
}
